package ysq.xyg.util;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.iherus.codegen.qrcode.SimpleQrcodeGenerator;

import java.io.FileOutputStream;
import java.io.OutputStream;

/**
 * 利用二维码生成器
 *
 * @author taocongcong
 * @create 2017-09-04 9:37
 */
public class QrcodeUtil {
    /**
     * 只生成纯二维码
     */
    public static String qrcode(String url,String newUrl) throws Exception {
        OutputStream out = null;

        try {
            out = new FileOutputStream(newUrl);
            // 生成图片的绝对引用地址
            String picUrl = StringUtils.replace(StringUtils.substringAfter(newUrl, ProProperties.getInstance().getBaseUploadURL()),"\\", "/");
            new SimpleQrcodeGenerator().generate(url).toStream(out);
            return picUrl;

        } finally {
            IOUtils.closeQuietly(out);
        }
    }
    /**
     * 只生成纯二维码
     */
    public static String qrcode(String url) throws Exception {
        OutputStream out = null;

        try {
            String newUrl = FilePathUtil.setFilePath();
            out = new FileOutputStream(newUrl);
            // 生成图片的绝对引用地址
            String picUrl = StringUtils.replace(StringUtils.substringAfter(newUrl, ProProperties.getInstance().getBaseUploadURL()),"\\", "/");
            new SimpleQrcodeGenerator().generate(url).toStream(out);
            return picUrl;

        } finally {
            IOUtils.closeQuietly(out);
        }
    }

    /**
     * 生成带图片的二维码
     * 在线图片
     *//*
    public static String qrcode(String imgUrl,String url) throws Exception {
        OutputStream out = null;

        try {
            String newUrl = FilePathUtil.setFilePath();
            out = new FileOutputStream(newUrl);
            // 生成图片的绝对引用地址
            String picUrl = StringUtils.replace(StringUtils.substringAfter(newUrl, ProProperties.getInstance().getBaseUploadURL()),"\\", "/");
            new SimpleQrcodeGenerator().setRemoteLogo(imgUrl).generate(url).toStream(out);
            return picUrl;

        } finally {
            IOUtils.closeQuietly(out);
        }
    }
*/
}
